using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Interfaces;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 营销活动实体
    /// 用于管理各种营销推广活动
    /// </summary>
    [Table("campaigns")]
    public class Campaign : ITenantEntity
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        [Key]
        public long Id { get; set; }

        /// <summary>
        /// 活动名称
        /// </summary>
        [Required]
        [StringLength(255)]
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 活动类型
        /// email=邮件营销, sms=短信营销, banner=横幅广告, popup=弹窗广告
        /// </summary>
        [Required]
        [StringLength(50)]
        public string Type { get; set; } = string.Empty;

        /// <summary>
        /// 活动描述
        /// </summary>
        [Column(TypeName = "text")]
        public string? Description { get; set; }

        /// <summary>
        /// 活动配置数据
        /// JSON格式存储活动相关的配置信息
        /// </summary>
        [Column(TypeName = "json")]
        public string? Data { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 状态（草稿/进行中/已结束/已暂停）
        /// 0=草稿, 1=进行中, 2=已结束, 3=已暂停
        /// </summary>
        public byte Status { get; set; }

        /// <summary>
        /// 预算金额
        /// </summary>
        [Column(TypeName = "decimal(10,2)")]
        public decimal? Budget { get; set; }

        /// <summary>
        /// 已花费金额
        /// </summary>
        [Column(TypeName = "decimal(10,2)")]
        public decimal SpentAmount { get; set; } = 0;

        /// <summary>
        /// 点击次数
        /// </summary>
        public int ClickCount { get; set; } = 0;

        /// <summary>
        /// 转化次数
        /// </summary>
        public int ConversionCount { get; set; } = 0;

        /// <summary>
        /// 创建人
        /// </summary>
        [Required]
        public long CreatedBy { get; set; }

        /// <summary>
        /// 修改人
        /// </summary>
        public long? UpdatedBy { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;

        /// <summary>
        /// 创建人导航属性
        /// </summary>
        [ForeignKey(nameof(CreatedBy))]
        public User? Creator { get; set; }

        /// <summary>
        /// 修改人导航属性
        /// </summary>
        [ForeignKey(nameof(UpdatedBy))]
        public User? Updater { get; set; }

        /// <summary>
        /// 租户标识符
        /// </summary>
        public string TenantId { get; set; } = string.Empty;
    }
}
